package com.project.shangqi.service.impl;

import com.project.shangqi.dto.FiberResult;
import com.project.shangqi.entity.VehicleFiber;
import com.project.shangqi.mapper.VehicleFiberMapper;
import com.project.shangqi.service.VehicleFiberService;
import com.project.shangqi.util.HttpUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class VehicleFiberServiceImpl implements VehicleFiberService {

    @Resource
    private VehicleFiberMapper vehicleFiberMapper;

    @Override
    public FiberResult getFromUrl(String token, String url, Integer timeout) throws Exception {
        HttpUtil httpUtil = new HttpUtil(url, token, timeout);
        FiberResult result = (FiberResult) httpUtil.getUrl(FiberResult.class, 0);
        return result;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insert(VehicleFiber entity) throws Exception {
        vehicleFiberMapper.insertSelective(entity);
    }
}
